import React,{useState} from 'react'
import { UploadOutlined } from '@ant-design/icons';
import { Button, message, Upload } from 'antd';
import type { UploadProps } from 'antd';
import { uploadImg } from '../../../api/goods';
export default function GoodsImg() {
  let token = localStorage.getItem("token") as string;
  let [imgList,setList] = useState<any[]>([])
  // 组件配置上传
//   const props: UploadProps = {
//   name: 'file',
//   action: 'http://119.3.122.213:8090/api/private/v1/upload',
//   headers: {
//     Authorization: token,
//   },
//   listType:"picture",
//   onChange(value){
//     console.log(value)
//   }
// }
  // 自定义上传
  const props:UploadProps<any> = {
    listType:"picture",
    fileList:imgList,
    customRequest(e:any){
      // 获取文件对象
      let file:any = e.file;
      console.log(file)
      let data:FormData = new FormData();
      data.append("file",file);
      uploadImg(data).then(res=>{
        if(res.data.meta.status ===200){
          console.log(res)
          let list = [...imgList];
          list.push({
            name:file.name,
            uid:file.uid,
            thumbUrl:`http://119.3.122.213:8090/${res.data.data.tmp_path}`
          })
          setList(list);
        }
      })
    }
  }
  return (
    <div>
      <Upload {...props}>
        <Button icon={<UploadOutlined />} type='primary'>上传商品图片</Button>
      </Upload>
    </div>
  )
}
